package RoomController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import Dao.RoomDao;

public class DetailRoom implements Controller{

	private RoomDao roomDao;
	
	public void setRoomDao(RoomDao roomDao) {
		this.roomDao = roomDao;
	}
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		
		ModelAndView mav = new ModelAndView();
		
		Integer R_NO = null;
		if(arg0.getParameter("ROOMNUM") != null){
			R_NO = Integer.parseInt(arg0.getParameter("ROOMNUM"));
		} else {
			mav.setViewName("redirect:index.jsp");
			return mav;
		}
		
		Object list = roomDao.roomPreview();
		Object data = roomDao.detailRoom(R_NO);
		
		mav.addObject("data",data);
		mav.addObject("list",list);
		mav.setViewName("detailroom");
		
		return mav;
	}
	
}
